<?php
/**
 * 过滤器链
 *
 * @version $Id: IFilterChain.php 312 2008-04-23 16:29:38Z iwind $
 * @package util.filter
 * @since 0.0.3
 */
class IFilterChain extends IObject {
	private $filters = array();
	private $object;
	
	/**
	 * 构造器
	 *
	 * @param mixed &$object 需要过滤的对象
	 * @since 0.0.3
	 */
	public function __construct(&$object) {
		$this->object = &$object;
	}
	
	/**
	 * 添加过滤器
	 *
	 * @param IFilter $filter 过滤器
	 * @since 0.0.3
	 */
	public function addFilter(IFilter $filter) {
		$this->filters[] = $filter;
	}
	
	/**
	 * 执行当前的过滤器
	 *
	 * @since 0.0.3
	 * @see doNextFilter
	 */
	public function doFilter() {
		$this->doNextFilter();
	}
	
	/**
	 * 执行链条中下一个过滤器
	 *
	 * @since 0.0.3
	 */
	public function doNextFilter() {
		$filter = current($this->filters);
		next($this->filters);
		if ($filter != null) {
			$filter->doFilter($this->object, $this);
		}
	}
	
	/**
	 * 取得filter列表
	 *
	 * @return array
	 * @since 0.0.3
	 */
	public function getFilters() {
		return $this->filters;
	}
}

?>